package logic

import (
	"HD_running/mall/order/api/internal/svc"
	"HD_running/mall/order/api/internal/types"
	"HD_running/mall/order/api/model"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegisterLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
	return &RegisterLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.RegisterResp, err error) {
	// todo: add your logic here and delete this line
	_, err = l.svcCtx.StudentcourseModel.Insert(l.ctx, &model.Studentcourse{
		Sno:       req.Sno,
		Cname:     req.Cname,
		Password1: req.Password,
		Sname:     req.Sname,
		Cno:       req.Cno,
	})
	if err != nil {
		return &types.RegisterResp{Msg: "账号已被注册"}, nil
	}

	return &types.RegisterResp{Msg: "注册成功"}, nil
}
